import { CurrentUser } from '@/decorators';
import {
  BillCheckDto,
  BillInfoDto,
  BillListDto,
  BillQueryDto,
  BillRefundDto,
  BillRejectDto,
  BillRollbackDto,
  BillWithdrawBatchDto,
  BillWithdrawDto,
} from '@/dtos';
import { BillService } from '@/services/bill.service';
import { ok } from '@/utils';
import { Body, Controller, Delete, Get, Param, Post } from '@nestjs/common';
import { BaseController } from './base.controller';

@Controller('bill')
export class BillController extends BaseController {
  constructor(private readonly billService: BillService) {
    super();
  }

  @Post('list')
  async getLogList(@Body() dto: BillListDto, @CurrentUser('id') id: number) {
    return ok(await this.billService.getList(id, dto));
  }

  @Get(':no')
  async getLogByNo(@Param('no') no: string) {
    return ok(await this.billService.getLogByNo(no));
  }

  @Delete(':no')
  async cancelLogByNo(@Param('no') no: string, @CurrentUser('id') id: number) {
    return ok(await this.billService.cancelLogByNo(no, id));
  }

  @Post('admin/query')
  async adminQuery(@Body() dto: BillQueryDto) {
    return ok(await this.billService.query(dto));
  }

  @Post('admin/refund')
  async adminRefund(@Body() dto: BillRefundDto) {
    return ok(await this.billService.refund(dto));
  }

  @Post('admin/check')
  async adminCheck(@Body() dto: BillCheckDto) {
    return ok(await this.billService.check(dto));
  }

  @Post('admin/check/batch')
  async adminCheckBatch() {
    return ok(await this.billService.checkBatch());
  }

  @Post('admin/withdraw')
  async adminWithdraw(@Body() dto: BillWithdrawDto) {
    return ok(await this.billService.withdraw(dto));
  }

  @Post('admin/withdraw/batch')
  async adminWithdrawBatch(@Body() dto: BillWithdrawBatchDto) {
    return ok(await this.billService.withdrawBatch(dto));
  }

  @Post('admin/reject')
  async adminReject(@Body() dto: BillRejectDto) {
    return ok(await this.billService.reject(dto));
  }

  @Post('admin/info')
  async adminInfo(@Body() dto: BillInfoDto) {
    return ok(await this.billService.info(dto));
  }

  @Post('admin/rollback')
  async adminRollback(@Body() dto: BillRollbackDto) {
    return ok(await this.billService.rollback(dto));
  }
}
